package a10_动态规划;

import java.util.Scanner;

/**
 * <p>
 * a18_完全背包理论基础复习2
 * </p>
 *
 * @author flyduck
 * @since 2025/2/25
 */
public class a18_完全背包理论基础复习2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int quantity = scanner.nextInt();
        int maxWeight = scanner.nextInt();

        int[] weight = new int[quantity];
        int[] value = new int[quantity];

        for (int i = 0; i < quantity; i++) {
            weight[i] = scanner.nextInt();
            value[i] = scanner.nextInt();
        }

        int[] dp = new int[maxWeight+1];
        dp[0] = 0;

        for (int i = 0; i < weight.length; i++) {
            for (int j = weight[i]; j <= maxWeight; j++) {
                dp[j] = Math.max(dp[j],dp[j-weight[i]] + value[i]);
            }
        }

        System.out.println(dp[maxWeight]);
    }
}
